<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/layui.css" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <script th:inline="none">
        layui.use(["table","layer"],function(){
            var table=layui.table;
            var layer=layui.layer;
            table.render({
                elem:"#stus",
                url:"/jwxt/studentlistbypage",
                page:true,
                toolbar:"#toolbarDemo",
                limit:5,
                cols: [[ //表头
                    {field: 'id', title: '编号', width:100, sort: true}
                    ,{field: 'name', title: '学生名称', width:180}
                    ,{field: 'password', title: '学生密码', width:180, sort: true}
                    ,{field: 'sex', title: '性别', width:80,templet: function(d){if(d.sex == 1){return '男'}else{return '女'}}}
                    ,{field: 'subject', title: '专业', width: 200}
                    ,{field: 'cname', title: '班级', width: 100}
                    ,{title:"操作",width: 200,toolbar:"#barDemo"}
                ]]
            })
            //监听头部工具栏事件
            table.on('toolbar(stutable)', function(obj){
                if(obj.event=="add"){
                    layer.open({
                        type:2,
                        title:"添加学生的列表",
                        area:["650px","500px"],
                        content:"/jwxt/toaddstudent"
                    })
                }
                // console.log(obj);
            })

            //监听行工具栏事件
            table.on('tool(stutable)', function(obj){
                if(obj.event=="update"){
                    layer.open({
                        title:"修改学生",
                        type:2,
                        area:["650px","500px"],
                        content:"/jwxt/toupdatestudent?id="+obj.data.id
                    })
                }else if(obj.event=="delete"){
                    layer.confirm('您确定要删除该数据吗？', {
                        btn: ['确定', '取消'] //可以无限个按钮
                    }, function(index, layero){
                        $.ajax({
                            url:"/jwxt/student/deletestudent",
                            data:{"id":obj.data.id},
                            type:"post",
                            dataType:"json",
                            success:function(dataJson){
                                if(dataJson.code==200){
                                    location.reload();
                                }else{
                                    layer.msg(dataJson.msg);
                                }
                            }
                        })
                    }, function(index){

                    })
                }
            })

        })
    </script>
    <!--    按键-->
    </script>
    <script id="toolbarDemo" type="text/html">
        <a class="layui-btn layui-btn-sm" lay-event="add">添加学生</a>
    </script>
    <script id="barDemo" type="text/html">
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">修改学生</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除学生</button>
    </script>

</head>
<body>
<table id="stus" lay-filter="stutable"></table>
</body>
</html>